package com.wc.acwing.贪心.平均;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/9 23:51
 * @description 平均
 * https://www.acwing.com/problem/content/5398/
 */
public class Main {
    static FastReader sc = new FastReader();

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        int[] m = new int[10];
        Arrays.sort(arr, (a, b) -> b[1] - a[1]);
        int t = n / 10;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (m[arr[i][0]] < t) {
                m[arr[i][0]]++;
            } else {
                ans += arr[i][1];
            }
        }
        System.out.println(ans);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
